package com.markerhub.mapper;

import com.markerhub.entity.TeachingStudentInClass;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TeachingStudentInClassMapper extends BaseMapper<TeachingStudentInClass> {
    /**
     * 根据班级ID查询学生ID列表
     *
     * @param classId 班级ID
     * @return 学生ID列表
     */
    @Select("SELECT student_id FROM m_teaching_student_in_class WHERE class_id = #{classId}")
    List<Integer> getStudentIdsByClassId(int classId);


    // 查询班级所有学生
    @Select("SELECT tsic.*, ms.stu_name as studentName, mc.name as className " +
            "FROM m_teaching_student_in_class tsic " +
            "INNER JOIN m_manager_student ms ON tsic.student_id = ms.id " +
            "INNER JOIN m_manager_class mc ON tsic.class_id = mc.id " +
            "WHERE tsic.class_id = #{classId}")
    List<TeachingStudentInClass> selectByClassId(Integer classId);

    // 查询学生所在的所有班级
    @Select("SELECT tsic.*, ms.stu_name as studentName, mc.name as className " +
            "FROM m_teaching_student_in_class tsic " +
            "INNER JOIN m_manager_student ms ON tsic.student_id = ms.id " +
            "INNER JOIN m_manager_class mc ON tsic.class_id = mc.id " +
            "WHERE tsic.student_id = #{studentId}")
    List<TeachingStudentInClass> selectByStudentId(Integer studentId);

    // 查询特定班级中的特定学生
    @Select("SELECT tsic.*, ms.stu_name as studentName, mc.name as className " +
            "FROM m_teaching_student_in_class tsic " +
            "INNER JOIN m_manager_student ms ON tsic.student_id = ms.id " +
            "INNER JOIN m_manager_class mc ON tsic.class_id = mc.id " +
            "WHERE tsic.class_id = #{classId} AND tsic.student_id = #{studentId}")
    TeachingStudentInClass selectByClassIdAndStudentId(@Param("classId") Integer classId,
                                               @Param("studentId") Integer studentId);
}
